package com.achievementmanagement.management.frame;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Arrays;
import java.util.List;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import org.pushingpixels.flamingo.api.common.JCommandButton;
import org.pushingpixels.flamingo.api.common.icon.ImageWrapperResizableIcon;
import org.pushingpixels.flamingo.api.ribbon.JRibbon;
import org.pushingpixels.flamingo.api.ribbon.JRibbonBand;
import org.pushingpixels.flamingo.api.ribbon.JRibbonFrame;
import org.pushingpixels.flamingo.api.ribbon.RibbonApplicationMenu;
import org.pushingpixels.flamingo.api.ribbon.RibbonApplicationMenuEntryFooter;
import org.pushingpixels.flamingo.api.ribbon.RibbonApplicationMenuEntryPrimary;
import org.pushingpixels.flamingo.api.ribbon.RibbonApplicationMenuEntrySecondary;
import org.pushingpixels.flamingo.api.ribbon.RibbonContextualTaskGroup;
import org.pushingpixels.flamingo.api.ribbon.RibbonElementPriority;
import org.pushingpixels.flamingo.api.ribbon.RibbonTask;
import org.pushingpixels.flamingo.api.ribbon.resize.CoreRibbonResizePolicies;
import org.pushingpixels.flamingo.api.ribbon.resize.IconRibbonBandResizePolicy;
public class MainFrame extends JRibbonFrame implements ActionListener{
	JRibbonBand band;
	RibbonTask task;
	RibbonContextualTaskGroup r;
	JCommandButton button1 = new JCommandButton("成绩录入", ImageWrapperResizableIcon.getIcon(ClassLoader.getSystemResource("res/inputico.png"), new Dimension(48, 48)));
	JCommandButton button2 = new JCommandButton("成绩管理", ImageWrapperResizableIcon.getIcon(ClassLoader.getSystemResource("res/manageico.png"), new Dimension(48, 48)));
	JCommandButton button5 = new JCommandButton("用户管理", ImageWrapperResizableIcon.getIcon(ClassLoader.getSystemResource("res/userico.png"), new Dimension(48, 48)));
	JCommandButton button6 = new JCommandButton("设置", ImageWrapperResizableIcon.getIcon(ClassLoader.getSystemResource("res/settingico.png"), new Dimension(48, 48)));
	JCommandButton button7 = new JCommandButton("退出", ImageWrapperResizableIcon.getIcon(ClassLoader.getSystemResource("res/exitpic.png"), new Dimension(48, 48)));
	JLabel bg = new JLabel(new ImageIcon(ClassLoader.getSystemResource("res/bg.jpg")));
	JPanel pnl1 = new JPanel();
	InputPanel pnl2 = new InputPanel();
	ManagePanel pnl3 = new ManagePanel();
	UserPanel pnl6 = new UserPanel();
	SettingPanel pnl7 = new SettingPanel();
	CardLayout layout = new CardLayout();
	private static final long serialVersionUID = 1L;
	static {
		try {
			javax.swing.UIManager.setLookAndFeel("org.pushingpixels.substance.api.skin.SubstanceOfficeBlue2007LookAndFeel");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public void build() {
//		System.out.println(this.getClass().getClassLoader().getResource("res/login.jpg").toString());
		this.setIconImage(new ImageIcon(ClassLoader.getSystemResource("res/ico.png")).getImage());
//		Image frame_icon=Toolkit.getDefaultToolkit().createImage(getClass().getResource("res/ico.jpg"));
//		this.setIconImage(frame_icon);
		this.setExtendedState(JFrame.MAXIMIZED_BOTH);
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
		RibbonApplicationMenu menu = new RibbonApplicationMenu();
		RibbonApplicationMenuEntryPrimary cjgl = new RibbonApplicationMenuEntryPrimary(ImageWrapperResizableIcon.getIcon(ClassLoader.getSystemResource("res/mngico.png"), new Dimension(48, 48)), "成绩管理", new ActionListener() {public void actionPerformed(ActionEvent e) {}}, JCommandButton.CommandButtonKind.POPUP_ONLY);
		RibbonApplicationMenuEntrySecondary minput = new RibbonApplicationMenuEntrySecondary(ImageWrapperResizableIcon.getIcon(ClassLoader.getSystemResource("res/inputico.png"), new Dimension(48, 48)), "录入成绩", new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				layout.show(pnl1, "1");
			}}, JCommandButton.CommandButtonKind.ACTION_ONLY);
		RibbonApplicationMenuEntrySecondary mmanage = new RibbonApplicationMenuEntrySecondary(ImageWrapperResizableIcon.getIcon(ClassLoader.getSystemResource("res/manageico.png"), new Dimension(48, 48)), "管理成绩",new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				layout.show(pnl1, "2");
			}}, JCommandButton.CommandButtonKind.ACTION_ONLY);
		cjgl.addSecondaryMenuGroup("成绩管理", minput,mmanage);
		RibbonApplicationMenuEntryPrimary pm = new RibbonApplicationMenuEntryPrimary(ImageWrapperResizableIcon.getIcon(ClassLoader.getSystemResource("res/settingico.png"), new Dimension(48, 48)), "设置", new ActionListener() {
	        public void actionPerformed(ActionEvent e) {
	        	layout.show(pnl1, "s");
	        }
	    }, JCommandButton.CommandButtonKind.ACTION_ONLY);
		RibbonApplicationMenuEntryPrimary user = new RibbonApplicationMenuEntryPrimary(ImageWrapperResizableIcon.getIcon(ClassLoader.getSystemResource("res/userico.png"), new Dimension(48, 48)), "用户管理", new ActionListener() {
	        public void actionPerformed(ActionEvent e) {
	        	layout.show(pnl1, "5");
	        }
	    }, JCommandButton.CommandButtonKind.ACTION_ONLY);
		RibbonApplicationMenuEntryFooter exit = new RibbonApplicationMenuEntryFooter(ImageWrapperResizableIcon.getIcon(ClassLoader.getSystemResource("res/exitpic.png"), new Dimension(48, 48)), "退出", new ActionListener() {
	        public void actionPerformed(ActionEvent e) {
	            System.exit(0);
	        }
	    });
		menu.addMenuEntry(cjgl);
		menu.addMenuEntry(pm);
		menu.addMenuEntry(user);
		menu.addFooterEntry(exit);
		this.getRibbon().setApplicationMenu(menu);
		this.setApplicationIcon(ImageWrapperResizableIcon.getIcon(ClassLoader.getSystemResource("res/ico.png"), new Dimension(48, 48)));
		dataGroup(this.getRibbon());
		{
			JRibbonBand band1 = new JRibbonBand("成绩管理", null);
			band1.setResizePolicies((List) Arrays.asList(new CoreRibbonResizePolicies.None(band1.getControlPanel()),
					new IconRibbonBandResizePolicy(band1.getControlPanel())));
			button1.addActionListener(this);
			button2.addActionListener(this);
			band1.addCommandButton(button1, RibbonElementPriority.MEDIUM);
			band1.addCommandButton(button2, RibbonElementPriority.MEDIUM);
			RibbonTask task1 = new RibbonTask("成绩管理", band1);
			this.getRibbon().addTask(task1);
		}
		{
			JRibbonBand band3 = new JRibbonBand("系统管理", null);
			band3.setResizePolicies((List) Arrays.asList(new CoreRibbonResizePolicies.None(band3.getControlPanel()),
					new IconRibbonBandResizePolicy(band3.getControlPanel())));
			button5.addActionListener(this);
			button6.addActionListener(this);
			button7.addActionListener(this);
			band3.addCommandButton(button5, RibbonElementPriority.MEDIUM);
			band3.addCommandButton(button6, RibbonElementPriority.MEDIUM);
			band3.addCommandButton(button7, RibbonElementPriority.MEDIUM);
			RibbonTask task3 = new RibbonTask("系统管理", band3);
			this.getRibbon().addTask(task3);
		}
		{
			this.add(pnl1,BorderLayout.CENTER);
			pnl1.setLayout(layout);
			pnl1.add(bg,"7");
			pnl1.add(pnl2,"1");
			pnl1.add(pnl3,"2");
			pnl1.add(pnl6,"5");
			pnl1.add(pnl7,"s");
		}
		this.setSize(800, 600);
		this.setTitle("\u91cd\u5e86\u5e02\u6c5f\u6d25\u533a\u56db\u724c\u574a\u5c0f\u5b66\u6821\u671f\u672b\u8003\u8bd5\u6210\u7ee9\u7ba1\u7406\u7cfb\u7edf_\u7ba1\u7406\u7aef");
		this.setVisible(true);
	}
	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getSource() == button1){
			layout.show(pnl1, "1");
		}else if(e.getSource() == button2){
			layout.show(pnl1, "2");
			this.getRibbon().setVisible(r, true);
		}else if(e.getSource() == button5){
			layout.show(pnl1, "5");
		}else if(e.getSource() == button6){
			layout.show(pnl1, "s");
		}else if(e.getSource() == button7){
			System.exit(0);
		}
	}
	@SuppressWarnings({ "unchecked", "rawtypes" })
	private void dataGroup(JRibbon ribbon) {
		//ContextualTaskGroup
		JCommandButton buttonx1 = new JCommandButton("更改数据",ImageWrapperResizableIcon.getIcon(ClassLoader.getSystemResource("res/editico.png"), new Dimension(48, 48)));
		JCommandButton buttonx2 = new JCommandButton("删除数据",ImageWrapperResizableIcon.getIcon(ClassLoader.getSystemResource("res/deleteico.png"), new Dimension(48, 48)));
		band = new JRibbonBand("数据管理",null);
		band.setResizePolicies((List) Arrays.asList(new CoreRibbonResizePolicies.None(band.getControlPanel()),
				new IconRibbonBandResizePolicy(band.getControlPanel())));
		band.addCommandButton(buttonx1, RibbonElementPriority.MEDIUM);
		band.addCommandButton(buttonx2, RibbonElementPriority.MEDIUM);
		task = new RibbonTask("数据管理",band);
		r = new RibbonContextualTaskGroup("数据管理", new Color(255, 50, 45),task); 
		ribbon.addContextualTaskGroup(r);
	}
}